package com.memo4android;

import com.memo4android.model.AppModel;
import com.memo4android.model.Dossier;
import com.memo4android.model.FolderAdapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;

public class InFolderActivity extends Activity implements OnClickListener {
	 private Dossier dossier;
	 Intent intent;
	 private FolderAdapter folderAdapter = null;

	
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.frame_dossier);
       
        Button buttonAddNote=(Button)findViewById(R.id.button_ajouter_icone_d);
        buttonAddNote.setOnClickListener(this);
        Button buttonAllTodos=(Button)findViewById(R.id.button_alltodos_d);
        buttonAllTodos.setOnClickListener(this);
        Button buttonAllNote=(Button)findViewById(R.id.button_allnotes_d);
        buttonAllNote.setOnClickListener(this);
        
        AppModel model = AppModel.getInstance(this);
        String folderName = getIntent().getStringExtra("folderName");
        setTitle(this.getTitle() + " - " + folderName);
        dossier = model.getDossier(folderName);
        if(dossier != null){ 
	        GridView gridview = (GridView) findViewById(R.id.tableau_memo_d);
	        folderAdapter = new FolderAdapter(this, dossier);
			gridview.setAdapter(folderAdapter);
        }
        
        intent =new Intent(this,NewNoteActivity.class);
        intent.putExtra("folderName", dossier.getTitre().toString());
    }
    
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        if(hasFocus && folderAdapter != null){
        	folderAdapter.notifyDataSetChanged();
        }
    }
    
    @Override
    public void onBackPressed(){
		Intent intent_allnotes = new Intent(this ,MainView.class);
		intent_allnotes.putExtra("label", "all notes");
		this.startActivity(intent_allnotes);    	
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
			case R.id.button_ajouter_icone_d:
				startActivity(intent);
				break;
			case R.id.button_alltodos_d:
				Intent intent_alltodo;
				intent_alltodo = new Intent(this ,ToDoListsActivity.class);
		        intent_alltodo.putExtra("label", "all todos");
				startActivity(intent_alltodo);
				break;
			case R.id.button_allnotes_d:
				Intent intent_allnotes = new Intent(this ,MainView.class);
				intent_allnotes.putExtra("label", "all notes");
				this.startActivity(intent_allnotes);
				break;
		}
		
	}
}